import Vue from "vue";
import { get, post2 } from "@/utils/request";
import request from "@/utils/request";

export function getCodeManager(codeDiv, callback) {
  if (!Vue.prototype.codeBox) Vue.prototype.codeBox = {};
  const newCode = [];
  codeDiv.split(",").forEach((item) => {
    if (!Vue.prototype.codeBox[item]) {
      newCode.push(item);
    }
  });
  if (newCode.length === 0) return callback && callback();
  get(
    {
      codeDiv: newCode.join(","),
    },
    "admin/getCodeManager"
  ).then((res) => {
    if (res.status === 200) {
      Vue.prototype.codeBox = {
        ...Vue.prototype.codeBox,
        ...res.data.data,
      };
      callback && callback();
    }
  });
}
export function codeToArray(code) {
  if (!Vue.prototype.codeBox) Vue.prototype.codeBox = {};
  if (Vue.prototype.codeBox[code]) {
    const list = [];
    for (const key in Vue.prototype.codeBox[code]) {
      list.push({
        name: Vue.prototype.codeBox[code][key],
        value: key,
      });
    }
    return list;
  }
  return [];
}

// 上传图片
export function uploadFileImage(parameter, callback) {
  return post2(parameter, "/uploadFileImage").then(callback);
}
//获取有效商家
export function getSellers() {
  return get({}, "/admin/seller/manage/getSellers");
}

// 获取全国订单分布数据
export function chinaorderJsonList(query) {
  return request({
    url: "/admin/report/chinaorderJson",
    method: "get",
    params: query,
  });
}

// 获取新增用户数据列表
export function fetchMemberListList(query) {
  return request({
    url: "/admin/member/member/list",
    method: "get",
    params: query,
  });
}

// 权限验证
export function checkPermissionRole(query) {
  return request({
    url: "/admin/checkPermission",
    method: "get",
    params: query,
  });
}
// 上传图片 返回mediaId
export function uploadCardImage(parameter, callback) {
  return post2(parameter, "/uploadCardImage").then(callback);
}
